#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
@author:atuo.cn
'''

from tkinter import *
from tkinter.ttk import *
from tkinter.filedialog import askopenfilename
from os import path

from dialogs.settingsdialog_layout import SettingsDialogLayout

class SettingsDialog(SettingsDialogLayout):
    
    def __init__(self, master, wmtitle,settings):
        print("settings dialog")
        self.settings=settings
        SettingsDialogLayout.__init__(self, master, wmtitle)

    def onLoad(self):
        print("onload")
        self.varKindlegen.set(self.settings.get("kindlegen",""))
        self.varKindlegenArgs.set(self.settings.get("kindlearg",""))
        
    #override methods of Dialog
    def apply(self):
        kinglegen=self.varKindlegen.get()
        kindlearg=self.varKindlegenArgs.get()
        section={}
        if kinglegen: section["kindlegen"]=kinglegen
        section["kindlearg"]=kindlearg
        self.settings.saveconfig({"kindlegen":section})
        self.settings["kindlegen"]=kinglegen or self.settings.default_values["kindlegen"]
        self.settings["kindlearg"]=kindlearg

    #Event Handlers
    def browse(self):
        file=askopenfilename()
        if file:
            self.varKindlegen.set(file)
